package com.epfresh.supplier.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.epfresh.api.entity.RequestEntityMapSupply;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.global.BaseActivity;
import com.epfresh.api.global.DataManager;
import com.epfresh.api.http.HttpRequest;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.api.utils.JsonUtils;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.supplier.R;
import com.epfresh.supplier.adapter.CategoryAdapter;
import com.epfresh.supplier.adapter.CategoryItemViewBinder;
import com.epfresh.supplier.adapter.CategoryTopAdapter;
import com.epfresh.supplier.adapter.PostViewBinder;
import com.epfresh.supplier.constant.Constant;
import com.epfresh.supplier.entity.Category;
import com.epfresh.supplier.entity.CategoryNames;
import com.epfresh.supplier.entity.CategoryOneEntity;
import com.epfresh.supplier.entity.CategoryThreeEntity;
import com.epfresh.supplier.entity.CategoryTwoEntity;
import com.epfresh.supplier.entity.Images;
import com.epfresh.supplier.entity.ProductAddEntity;
import com.epfresh.supplier.entity.StoreInfo;
import com.epfresh.supplier.entity.TagPackage;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

import multitype.MultiTypeAdapter;
import multitype.OnRecyclerViewItemClickListener;
import multitype.suspension.ISuspensionInterface;
import multitype.suspension.SuspensionDecoration;

public class ProductAddCategoryActivity extends BaseActivity {
    private ListView lv;//二级列表

    private RecyclerView recyclerView;//一级列表
    private RecyclerView rvCategory;//三级列表

    private CategoryAdapter adapter;
    CategoryTopAdapter categoryTopAdapter;
    MultiTypeAdapter multiAdapter;


    private List<CategoryOneEntity> list = new ArrayList<>();
    private List<CategoryNames> listVarieties = new ArrayList<>();
    private List<CategoryTwoEntity> listCategory = new ArrayList<>();
    private List<ISuspensionInterface> items = new ArrayList<>();

    SuspensionDecoration mDecoration;
//    private TagAdapter<CategoryNames> tagAdapter;

    private String nameId;
    private String categoryId;
    private String topCategoryId;

    int tagW = -1;
    int tagAllW = -1;
    GridLayoutManager layoutManager2;

    ProductAddEntity productAddEntity;
    private String productType;
    boolean isCategoryClick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_add_category_all);
        if (savedInstanceState != null) {
            getIntent().putExtra("nameId", savedInstanceState.getString("nameId"));
            getIntent().putExtra("categoryId", savedInstanceState.getString("categoryId"));
            getIntent().putExtra("topCategoryId", savedInstanceState.getString("topCategoryId"));
            getIntent().putExtra("productAddEntity", savedInstanceState.getString("productAddEntity"));
            getIntent().putExtra(Constant.TYPE, savedInstanceState.getString(Constant.TYPE));
        }
        nameId = getIntent().getStringExtra("nameId");
        categoryId = getIntent().getStringExtra("categoryId");
        topCategoryId = getIntent().getStringExtra("topCategoryId");
        productType = getIntent().getStringExtra(Constant.TYPE);
        ivBack.setVisibility(View.VISIBLE);
        tvBack.setVisibility(View.VISIBLE);
        toolbarTitle.setText("选择品类");
        rightbtn.setText(getString(R.string.help));
        rightbtn.setTextColor(0xff898989);
        rightbtn.setVisibility(View.VISIBLE);
        rightbtn.setOnClickListener(this);
        initView();

        String s = getIntent().getStringExtra("productAddEntity");
        Log.e("productAddEntity","productAddEntity:"+s);
        if (s != null && !"".equals(s)){
            this.productAddEntity = new Gson().fromJson(s,ProductAddEntity.class);
        }else {
            this.productAddEntity = new ProductAddEntity();

        }
        this.productAddEntity.setType(productType);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        setIntent(intent);
    }

    @Override
    protected void onToolbarBack() {
        onBackPressed();
    }

    @Override
    public void onBackPressed() {

        if (getIntent().getBooleanExtra("is_reset_category",false)){
            getIntent().putExtra("is_reset_category",false);
            Log.e("onBackPressed","dsafadsfasdfsdaf");
            intoProductAdd();
            return;
        }

        super.onBackPressed();
    }

    private void intoProductAdd(){
        Intent intent = new Intent(this, ProductAddActivity.class);
        String productType = productAddEntity.getType();
        //现售1
        intent.putExtra(Constant.TYPE, productType);


        intent.putExtra("is_first", true);

        intent.putExtra("isCategoryType", getIntent().getBooleanExtra("isCategoryType",false));

//        intent.putExtra("tagPackage", getIntent().getStringExtra("tagPackage"));
        if(tagPackage != null)
            intent.putExtra("tagPackage", new Gson().toJson(tagPackage));

        startActivity(intent);
    }



    @Override
    protected void onRestart() {
        super.onRestart();

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putString("nameId", nameId);
        outState.putString("categoryId", categoryId);
        outState.putString("topCategoryId", topCategoryId);
        outState.putString("productAddEntity", getIntent().getStringExtra("productAddEntity"));
        outState.putString(Constant.TYPE, productType);
        super.onSaveInstanceState(outState);
    }

    private void initView() {
        tagW = LocalDisplay.SCREEN_WIDTH_PIXELS - getResources().getDimensionPixelSize(R.dimen.category_list_width) - LocalDisplay.dp2px(4) * 8;
        tagAllW = LocalDisplay.SCREEN_WIDTH_PIXELS - getResources().getDimensionPixelSize(R.dimen.category_list_width) - LocalDisplay.dp2px(4) * 2;
        tagW /= 3;
        lv = (ListView) findViewById(R.id.lv);
        recyclerView = (RecyclerView) findViewById(R.id.ly_navigation);
        rvCategory = (RecyclerView) findViewById(R.id.lv_category);

        adapter = new CategoryAdapter(this, listCategory);
        lv.setAdapter(adapter);

        adapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listCategory.size() > position) {
                    CategoryTwoEntity categoryTwoEntity = listCategory.get(position);
                    int p = categoryTwoEntity.getPosition();
                    isCategoryClick = true;
                    if (p < items.size()) {
                        layoutManager2.scrollToPositionWithOffset(p, 0);
                    }
                }



            }
        });


        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        categoryTopAdapter = new CategoryTopAdapter();
        recyclerView.setAdapter(categoryTopAdapter);
        categoryTopAdapter.setCategory(list);


        categoryTopAdapter.setOnRecyclerViewItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object data) {
                if (data instanceof CategoryOneEntity){
                    CategoryOneEntity ca = (CategoryOneEntity) data;
                    ca.setSelect(true);

                    for (int i = 0; i < list.size(); i++) {
                        CategoryOneEntity categoryOneEntity = list.get(i);
                        if (ca.equals(categoryOneEntity)) {
                            categoryOneEntity.setSelect(true);
                        } else {
                            categoryOneEntity.setSelect(false);
                        }
                    }
                    categoryTopAdapter.notifyDataSetChanged();
                    List<CategoryTwoEntity> categoryTwoEntities = ca.getItem();
                    updateData(categoryTwoEntities);
                }
            }
        });

        multiAdapter = new MultiTypeAdapter();
        PostViewBinder postViewBinder = new PostViewBinder();
        postViewBinder.setOnRecyclerViewItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object data) {
                //position always -1
                if (data != null) {
                    intoNext((CategoryThreeEntity) data);
                }
            }
        });
        multiAdapter.register(CategoryThreeEntity.class, postViewBinder);
        multiAdapter.register(CategoryTwoEntity.class, new CategoryItemViewBinder());
        layoutManager2 = new GridLayoutManager(this, 3);
        GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                Object item = items.get(position);
                return (item instanceof CategoryTwoEntity) ? 3 : 1;
            }
        };
        layoutManager2.setSpanSizeLookup(spanSizeLookup);

//        int space = LocalDisplay.dp2px(12);
//        rvCategory.addItemDecoration(new (space, spanSizeLookup));


        rvCategory.setLayoutManager(layoutManager2);
        rvCategory.setAdapter(multiAdapter);
        multiAdapter.setItems(items);


        rvCategory.addItemDecoration(mDecoration = new SuspensionDecoration(this, items));

        mDecoration.setOnFloatChangeListener(new SuspensionDecoration.OnFloatChangeListener() {
            @Override
            public void onFloatChangeListener(int position, ISuspensionInterface is) {

                if (is != null ) {
                    if (isCategoryClick){
                        isCategoryClick = false;
                        return;
                    }
                    String suspensionTagId = is.getSuspensionTagId();
                    Log.i("suspensionTagId_",suspensionTagId);
                    if (suspensionTagId != null) {
                        for (int i = 0; i < listCategory.size(); i++) {
                            CategoryTwoEntity categoryTwoEntity = listCategory.get(i);
                            if (suspensionTagId.equals(categoryTwoEntity.getId())) {
                                categoryTwoEntity.setSelect(true);
                                lv.smoothScrollToPosition(i);
                            } else {
                                categoryTwoEntity.setSelect(false);
                            }
                        }

                        adapter.notifyDataSetChanged();
                    }
                }
            }
        });
        mDecoration.setTitleFontSize(LocalDisplay.dp2px(12));
        mDecoration.setmDatas(items);
        multiAdapter.notifyDataSetChanged();
        requestCategory();
    }

    private void layoutFloatDown() {
        int firstVisibleItemPosition = layoutManager2.findFirstVisibleItemPosition();
        int firstCompletelyVisibleItemPosition = layoutManager2.findFirstCompletelyVisibleItemPosition();
        ISuspensionInterface is1 = items.get(firstVisibleItemPosition);
        Log.e("is", "id:" + is1.getSuspensionTagId() + "--name:" + is1.getSuspensionTag());
        Log.e("is", "firstVisibleItemPosition:" + firstVisibleItemPosition + "--firstCompletelyVisibleItemPosition:" + firstCompletelyVisibleItemPosition);
        if (firstCompletelyVisibleItemPosition - firstVisibleItemPosition < 2) {
            ISuspensionInterface is = items.get(firstVisibleItemPosition);
            String suspensionTagId = is.getSuspensionTagId();
            Log.d("is", "-------firstVisibleItemPosition:" + firstVisibleItemPosition + "--firstCompletelyVisibleItemPosition:" + firstCompletelyVisibleItemPosition);

//            if (is instanceof Category) {

            if (suspensionTagId != null) {
                for (int i = 0; i < listCategory.size(); i++) {
                    CategoryTwoEntity categoryTwoEntity = listCategory.get(i);
//                    if (is.equals(category)) {
                    if (suspensionTagId != null && suspensionTagId.equals(categoryTwoEntity.getId())) {
                        categoryTwoEntity.setSelect(true);
                        lv.smoothScrollToPosition(i);
                    } else {
                        categoryTwoEntity.setSelect(false);
                    }
                }

                adapter.notifyDataSetChanged();
//            }
            }
        }
    }


    public void intoNext(CategoryThreeEntity cn) {
/** 一级分类ID */
//        private Long topCategoryId;
/** 二级分类ID */
//        private Long categoryId;
/** 二级分类类型，1：平台，2：自建 */
//        private Integer categoryType;
/** 品类Id */
//        private Long nameId;

        String id = String.valueOf(productAddEntity.getId());

        String categoryTopOldId = productAddEntity.getTopCategoryId();
        String categoryOldId = productAddEntity.getCategoryId();
        String nameOldId = productAddEntity.getNameId();

        String categoryTopId = cn.getGrandParentId();
        String categoryId = cn.getParentId();
        String nameId = cn.getId();






        productAddEntity.setCategoryId(cn.getParentId());
        productAddEntity.setCategoryName(cn.getParentName());
        productAddEntity.setNameId(cn.getId());
        productAddEntity.setNames(cn.getName());
//        productAddEntity.setCategoryType(cn.getCategoryType());
        productAddEntity.setTopCategoryId(cn.getGrandParentId());
        if(productAddEntity.getName()==null)
            productAddEntity.setName(new Category());
        productAddEntity.getName().setMoml(cn.isMoml());
        productAddEntity.getName().setType(cn.getType());

        DataManager.getInstance().setProductAddEntity(productAddEntity);




        Intent intent = new Intent(this, ProductAddActivity.class);
        String productType = productAddEntity.getType();
        //现售1
        intent.putExtra(Constant.TYPE, productType);

        String imagesBanner = getIntent().getStringExtra("imagesBanner");
        String imagesDetail = getIntent().getStringExtra("imagesDetail");

        if (imagesBanner != null && !"".equals(imagesBanner)){
            List<Images> imagesBannerList = JsonUtils.fromJsonObject(imagesBanner,List.class,Images.class);

            if (imagesBannerList != null ){
                productAddEntity.setImagesBanner(imagesBannerList);
            }

        }
        if (imagesDetail != null && !"".equals(imagesDetail)){
            List<Images> imagesBannerList = JsonUtils.fromJsonObject(imagesDetail,List.class,Images.class);

            if (imagesBannerList != null ){
                productAddEntity.setImagesDetail(imagesBannerList);
            }

        }
        Log.e("imagelist","imagesBanner:"+imagesBanner);
        Log.e("imagelist","imagesDetail:"+imagesDetail);


        if (id != null && !"".equals(id)){

            intent.putExtra("is_first", false);

            if (categoryTopId != null && categoryId != null && nameId != null
                    &&!"".equals(categoryTopId)
                    &&!"".equals(categoryId)
                    &&!"".equals(nameId)
                    && categoryTopId.equals(categoryTopOldId)
                    && categoryId.equals(categoryOldId)
                    ){
                //分类不需要清除
                intent.putExtra("is_classify_same", true);
                if (nameId.equals(nameOldId)){
                    intent.putExtra("is_same", true);
                }else {
                    productAddEntity.setSpecies(null);
                }
            }else {
                productAddEntity.setStoreCategoryName(null);
            }

        }else {
            intent.putExtra("is_first", true);
        }
        intent.putExtra("isCategoryType", cn.isCategoryType());
        getIntent().putExtra("is_reset_category",false);
//        intent.putExtra("tagPackage", getIntent().getStringExtra("tagPackage"));
        if(tagPackage != null)
            intent.putExtra("tagPackage", new Gson().toJson(tagPackage));
        if(getIntent().getBooleanExtra("is_draft",false)){
            intent.putExtra("productAddEntity",new Gson().toJson(productAddEntity));
            setResult(RESULT_OK,intent);
            finish();
            return;
        }

        intent.putExtra("pinlei",cn.getName());
        intent.putExtra("moml",cn.isMoml());
        startActivityForResult(intent,0x1234);

       /* if (cn.isCategoryType()) {//品类如果品类类型是分类时，需要显示品名字段
            intoSpecies(cn);
        } else {
            intoVariety(cn);
        }
*/

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(resultCode == RESULT_OK && requestCode == 0x1234){
            boolean isClear = data.getBooleanExtra("isClear", false);
            if (isClear){
                productAddEntity = new ProductAddEntity();
                this.productAddEntity.setType(productType);
            }
        }
    }

    private void intoSpecies(CategoryNames cn) {
        Intent intent = new Intent(this, ProductAddOtherActivity.class);
        intent.putExtra("page_type", "5");
        intent.putExtra("content", cn.getName());

        //三级
        intent.putExtra("nameId", cn.getId());
        if(tagPackage != null)
        intent.putExtra("tagPackage", new Gson().toJson(tagPackage));
        startActivity(intent);
    }
    private void intoVariety(CategoryNames cn) {
        Intent intent = new Intent(this, ProductAddCategoryVarietiesActivity.class);
//        intent.putExtra("categoryId", cn.getGrandParentId());
        intent.putExtra("nameId", cn.getId());
        if(tagPackage != null)
        intent.putExtra("tagPackage", new Gson().toJson(tagPackage));
        startActivity(intent);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.tv_btn:

                break;
            case R.id.rightbtn:
                help();
                break;
        }
    }
    private void help() {
        Intent intent = new Intent(this, WebActivity.class);
        StoreInfo storeInfo = getStoreInfo();
        if (storeInfo != null && storeInfo.isDc()) {
            intent.putExtra(Constant.KEY_WEB_URL, Constant.URL_HELP_PRODUCT_DC);
        } else {
            intent.putExtra(Constant.KEY_WEB_URL, Constant.URL_HELP_PRODUCT);

        }
        intent.putExtra(Constant.KEY_WEB_TITLE, getString(R.string.help));
        startActivity(intent);
    }

    public void requestCategory() {

        RequestEntityMapSupply RequestEntityMapSupply = new RequestEntityMapSupply();
        RequestEntityMapSupply.setCmd(com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_category_tree);
        request(RequestEntityMapSupply, com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_category_tree, onCategoryTreeRequestListener);

    }


    private OnRequestListener<List<CategoryOneEntity>> onCategoryTreeRequestListener = new OnRequestListener<List<CategoryOneEntity>>() {
        @Override
        public List<CategoryOneEntity> jsonToObj(String responseStr) {
            List<CategoryOneEntity> o = new Gson().fromJson(responseStr, new TypeToken<List<CategoryOneEntity>>() {
            }.getType());

            if (o != null) {
                for (int i = 0; i < o.size(); i++) {
                    CategoryOneEntity categoryOneEntity = o.get(i);
                    if (categoryOneEntity != null) {
                        List<CategoryTwoEntity> categoryTwoEntities = categoryOneEntity.getItem();
                        if (categoryTwoEntities != null) {
                            for (int j = 0; j < categoryTwoEntities.size(); j++) {
                                CategoryTwoEntity categoryTwoEntity = categoryTwoEntities.get(j);
                                if (categoryTwoEntity != null) {//todo:目前该接口正在调整中
/*                                    List<CategoryNames> names = category.getNames();
                                    for (int k = 0; k < names.size(); k++) {
                                        CategoryNames categoryNames = names.get(k);
                                        if (categoryNames != null) {
                                            categoryNames.setParentId(category.getId());
                                            categoryNames.setParentName(category.getName());
                                            categoryNames.setGrandParentId(categoryAll.getId());
                                            categoryNames.setCategoryType(category.getType());

                                            categoryNames.setGrandParentName(categoryAll.getName());
                                        }
                                    }*/
                                }
                            }
                        }
                    }
                }
            }
            return o;
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            showExceptionView(R.mipmap.icon_error, "网络错误", HttpRequest.FAIL_NET_FAULT);
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            showExceptionView(R.mipmap.icon_error, arg + "", HttpRequest.FAIL_NET_FAULT);
        }

        @Override
        public void onStart(Object tag) {
            showProgressView();
        }

        @Override
        public void onResponse(ResponseEntity<List<CategoryOneEntity>> response, Object tag) {

            List<CategoryOneEntity> categoryOneEntities = response.getResponseElement();
            for (CategoryOneEntity categoryOneEntity : categoryOneEntities) {
                String oneId = String.valueOf(categoryOneEntity.getId());
                List<CategoryTwoEntity> categoryTwoEntities = categoryOneEntity.getItem();

                for (CategoryTwoEntity categoryTwoEntity : categoryTwoEntities) {
                    String twoId = categoryTwoEntity.getId();
                    List<CategoryThreeEntity> categoryThreeEntities = categoryTwoEntity.getItem();

                    for (CategoryThreeEntity categoryThreeEntity : categoryThreeEntities) {
                        categoryThreeEntity.setParentId(twoId);
                        categoryThreeEntity.setGrandParentId(oneId);
                    }
                }
            }

            if (categoryOneEntities != null && categoryOneEntities.size() > 0) {
                list.clear();
                list.addAll(categoryOneEntities);

                if (list.size() > 0){
                    CategoryOneEntity categoryOneEntity = list.get(0);
                    categoryOneEntity.setSelect(true);
                    List<CategoryTwoEntity> categoryTwoEntities = categoryOneEntity.getItem();

                    updateData(categoryTwoEntities);
                }


                categoryTopAdapter.notifyDataSetChanged();

                requestTagList();


            } else {
                showExceptionView(R.mipmap.icon_error, "没有数据", HttpRequest.FAIL_DATA_EMPTY);
            }
        }
    };

    private void updateData(List<CategoryTwoEntity> categoryTwoEntities) {
        items.clear();
//        multiAdapter.notifyItemRangeRemoved(0, s);
        for (int j = 0; j < categoryTwoEntities.size(); j++) {
            CategoryTwoEntity categoryTwoEntity = categoryTwoEntities.get(j);
            int size = items.size();
            categoryTwoEntity.setPosition(size);
            items.add(categoryTwoEntity);
            List<CategoryThreeEntity> categoryThreeEntities = categoryTwoEntity.getItem();
            for (int k = 0; k < categoryThreeEntities.size(); k++) {
                CategoryThreeEntity categoryThreeEntity = categoryThreeEntities.get(k);
                categoryThreeEntity.setParentName(categoryTwoEntity.getName());
                items.add(categoryThreeEntity);
            }
        }

        Log.e("items","item_size:"+items.size());
        listCategory.clear();
        if (categoryTwoEntities.size() > 0) {
            categoryTwoEntities.get(0).setSelect(true);
        }
        listCategory.addAll(categoryTwoEntities);

        multiAdapter.notifyDataSetChanged();
        rvCategory.scrollToPosition(0);
        adapter.notifyDataSetChanged();
    }

    private void requestTagList() {
        RequestEntityMapSupply RequestEntityMapSupply = new RequestEntityMapSupply();
        RequestEntityMapSupply.setCmd(com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_tag_list);
        //1：商品标签；2：店铺标签
        RequestEntityMapSupply.putParameter("type", "1");
        //1散货,0整货
        if (getStoreInfo() != null && getStoreInfo().isDc()) {
            RequestEntityMapSupply.putParameter("isDc", "1");
        } else {
            RequestEntityMapSupply.putParameter("isDc", "0");
        }
//        requestTag.type = RequestTag.TYPE_CURRENT;
        request(RequestEntityMapSupply, com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_tag_list, onTagListRequestListener);

    }

    private TagPackage tagPackage;
    private OnRequestListener<TagPackage> onTagListRequestListener = new OnRequestListener<TagPackage>() {
        @Override
        public TagPackage jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, TagPackage.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {

            showExceptionView(R.mipmap.icon_error, "网络错误", HttpRequest.FAIL_NET_FAULT);
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            showExceptionView(R.mipmap.icon_error, arg + "", HttpRequest.FAIL_NET_FAULT);
        }

        @Override
        public void onStart(Object tag) {

        }

        @Override
        public void onResponse(ResponseEntity<TagPackage> response, Object tag) {

            showMainView();

            TagPackage responseElement = response.getResponseElement();

            if (responseElement != null) {
                showMainView();
                tagPackage = responseElement;

            }
        }
    };


}
